<?
	require_once('db/table.php');
	
	abstract class db_abstract
	{
		protected $db;
		
		
		public function __construct(mysqli $iDb)
		{
			$this -> db = $iDb;
						
		}
		
		
		
		
		public function getDbTable($iTableName)
		{
			$Dt = new db_table();
			if ($result =  $this -> db -> query('SELECT '. $iTableName .' FROM postcode'))
			{
			$count = $result ->num_rows;
			echo $count;
			
				while ($row = $result->fetch_assoc()) 
				{
					$dataRow = $Dt -> newRow();
					foreach($row as $key => $value)
					{
						$dataRow -> addColumn($key,$value);
					}
				}

			}
			return $Dt;
		}
		
		
		/*
			@author		Jelle Versele
			
			functie voor het controleren van een combinatie in de databank
			bv: het controlleren van een paswoord en gebruikersnaam
		*/
		
		public function findInDb(array $iValues, $iTable){
			
			
			
			$array = array();	
			$sql = "SELECT * FROM ". $iTable ." WHERE ";
			
			$i = 0;
			
			foreach($iValues as $key => $value){
				$i ++;
				
				$sql .= $key . " = ?";
				
				$array[] = $value;		
				
				if($i < count($iValues)){
					$sql .= " AND ";
				}
				
			}
			
			
		
			$query = $this -> db -> prepare($sql);
			
			$query = $this -> bindVars($query, $array);
			
			$query -> execute();
			
			$query->store_result();
		
			
			
		
			return $query -> num_rows() > 0 ? true : false;
			
			
			
			 
			
		}
		

		/*
		
		function voor het automatisch
		binden van een aantal variable
		
		*/
		public function bindVars(mysqli_stmt $stmt,array $params) {
		
		     	
			$types = '';                        
        	
			foreach($params as $param){        
            	
				if(is_int($param)){
                	$types .= 'i';              
            	}elseif (is_float($param)){
                	$types .= 'd';              
            	}elseif (is_string($param)){
                	$types .= 's';              
            	}else{
                	$types .= 'b';              
            	}
        }
 
        
		$binds[] = $types;             
                                            
 
      	foreach($params as $param){
            $binds[] = $param;  
        }
 
                                            
        call_user_func_array(array($stmt,'bind_param'),$binds);
	    
		return $stmt;                           
	}

}


?>
